/* 
 * File:   ClientConfFileManagerTest.cpp
 * Author: nahuel
 *
 * Created on May 19, 2013, 9:12:22 PM
 */

#include <stdlib.h>
#include <iostream>
#include "common_ClientConfFileManager.h"
using namespace TP;

/*
 * Simple C++ Test Suite
 */

// Debe existir el directorio ".au" en el home (reemplazar con tu nombre de usuario!!!)
const char* path = "/home/nahuel/.au/TestXMLCliente2.xml";

void testClientConfFileManager() {
    //const std::string& filePath("~/.au/TestXMLCliente.xml");
    //const std::string& filePath("/home/nahuel/Desktop/TestXMLCliente.xml");
    const std::string& filePath(path);
    
    ClientConfFileManager clientConfFileManager(filePath);
    clientConfFileManager.SaveChanges();
    
    if (false) {
        std::cout << "%TEST_FAILED% time=0 testname=testClientConfFileManager (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}

//void testSaveChanges() {
//    ClientConfFileManager clientConfFileManager;
//    clientConfFileManager.SaveChanges();
//    if (true /*check result*/) {
//        std::cout << "%TEST_FAILED% time=0 testname=testSaveChanges (ClientConfFileManagerTest) message=error message sample" << std::endl;
//    }
//}

void testSetIntervaloPolling() {
    unsigned int intervaloPolling = 123;
    const std::string& filePath(path);
    
    ClientConfFileManager clientConfFileManager(filePath);    
    clientConfFileManager.SetIntervaloPolling(intervaloPolling);    
    clientConfFileManager.SaveChanges();    
    
    if (false) {
        std::cout << "%TEST_FAILED% time=0 testname=testSetIntervaloPolling (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}

void testSetIpServidor() {
    const std::string& ipServidor = "127.0.0.1";
    const std::string& filePath(path);
    
    ClientConfFileManager clientConfFileManager(filePath);    
    clientConfFileManager.SetIpServidor(ipServidor);    
    clientConfFileManager.SaveChanges();    
    
    if (false) {
        std::cout << "%TEST_FAILED% time=0 testname=testSetIpServidor (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}

void testSetPassword() {
    const std::string& password = "qwerty";
    const std::string& filePath(path);
    
    ClientConfFileManager clientConfFileManager(filePath);    
    clientConfFileManager.SetPassword(password);    
    clientConfFileManager.SaveChanges();    
    
    if (false) {
        std::cout << "%TEST_FAILED% time=0 testname=testSetPassword (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}

void testSetPathAU() {
    const std::string& pathAu("/example/path2");
    const std::string& filePath(path);
    
    ClientConfFileManager clientConfFileManager(filePath);    
    clientConfFileManager.SetPathAU(pathAu);    
    clientConfFileManager.SaveChanges();    
    
    if (false) {
        std::cout << "%TEST_FAILED% time=0 testname=testSetPathAU (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}

void testSetPuertoServidor() {
    const std::string puertoServidor("8080");
    const std::string& filePath(path);
    
    ClientConfFileManager clientConfFileManager(filePath);    
    clientConfFileManager.SetPuertoServidor(puertoServidor);    
    clientConfFileManager.SaveChanges();    
    
    if (false) {
        std::cout << "%TEST_FAILED% time=0 testname=testSetPuertoServidor (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}

void testSetUsuario() {
    const std::string& usuario = "username";
    const std::string& filePath(path);
    
    ClientConfFileManager clientConfFileManager(filePath);    
    clientConfFileManager.SetUsuario(usuario);    
    clientConfFileManager.SaveChanges();    
    
    if (false) {
        std::cout << "%TEST_FAILED% time=0 testname=testSetUsuario (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}


/***************************     Getters        *******************************/

void testGetIntervaloPolling() {
    const std::string& filePath(path);    
    ClientConfFileManager clientConfFileManager(filePath);
    unsigned int intervaloPolling = clientConfFileManager.GetIntervaloPolling();    
    
    if (intervaloPolling != 123) {
        std::cout << "%TEST_FAILED% time=0 testname=testGetIntervaloPolling (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}

void testGetIpServidor() {
    const std::string& filePath(path);    
    ClientConfFileManager clientConfFileManager(filePath);
    std::string ip = clientConfFileManager.GetIpServidor(); 
    
    if (ip != "127.0.0.1") {
        std::cout << "%TEST_FAILED% time=0 testname=testGetIpServidor (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}

void testGetPassword() {
    const std::string& filePath(path);    
    ClientConfFileManager clientConfFileManager(filePath);
    std::string password = clientConfFileManager.GetPassword(); 
    
    if (password != "qwerty") {
        std::cout << "%TEST_FAILED% time=0 testname=testGetPassword (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}

void testGetPathAU() {
    const std::string& filePath(path);    
    ClientConfFileManager clientConfFileManager(filePath);
    std::string pathAU = clientConfFileManager.GetPathAU(); 
    
    if (pathAU != "/example/path2") {
        std::cout << "%TEST_FAILED% time=0 testname=testGetPathAU (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}

void testGetPuertoServidor() {
    const std::string& filePath(path);    
    ClientConfFileManager clientConfFileManager(filePath);
    std::string puerto = clientConfFileManager.GetPuertoServidor(); 
    
    if (puerto != "8080") {
        std::cout << "%TEST_FAILED% time=0 testname=testGetPuertoServidor (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}

void testGetUsuario() {
    const std::string& filePath(path);    
    ClientConfFileManager clientConfFileManager(filePath);
    std::string usuario = clientConfFileManager.GetUsuario(); 
    
    if (usuario != "username") {
        std::cout << "%TEST_FAILED% time=0 testname=testGetUsuario (ClientConfFileManagerTest) message=error message sample" << std::endl;
    }
}

int main(int argc, char** argv) {
    std::cout << "%SUITE_STARTING% ClientConfFileManagerTest" << std::endl;
    std::cout << "%SUITE_STARTED%" << std::endl;

    std::cout << "%TEST_STARTED% testClientConfFileManager (ClientConfFileManagerTest)" << std::endl;
    testClientConfFileManager();
    std::cout << "%TEST_FINISHED% time=0 testClientConfFileManager (ClientConfFileManagerTest)" << std::endl;

//    std::cout << "%TEST_STARTED% testSaveChanges (ClientConfFileManagerTest)" << std::endl;
//    testSaveChanges();
//    std::cout << "%TEST_FINISHED% time=0 testSaveChanges (ClientConfFileManagerTest)" << std::endl;

    std::cout << "%TEST_STARTED% testSetIntervaloPolling (ClientConfFileManagerTest)" << std::endl;
    testSetIntervaloPolling();
    std::cout << "%TEST_FINISHED% time=0 testSetIntervaloPolling (ClientConfFileManagerTest)" << std::endl;

    std::cout << "%TEST_STARTED% testSetIpServidor (ClientConfFileManagerTest)" << std::endl;
    testSetIpServidor();
    std::cout << "%TEST_FINISHED% time=0 testSetIpServidor (ClientConfFileManagerTest)" << std::endl;

    std::cout << "%TEST_STARTED% testSetPassword (ClientConfFileManagerTest)" << std::endl;
    testSetPassword();
    std::cout << "%TEST_FINISHED% time=0 testSetPassword (ClientConfFileManagerTest)" << std::endl;

    std::cout << "%TEST_STARTED% testSetPathAU (ClientConfFileManagerTest)" << std::endl;
    testSetPathAU();
    std::cout << "%TEST_FINISHED% time=0 testSetPathAU (ClientConfFileManagerTest)" << std::endl;

    std::cout << "%TEST_STARTED% testSetPuertoServidor (ClientConfFileManagerTest)" << std::endl;
    testSetPuertoServidor();
    std::cout << "%TEST_FINISHED% time=0 testSetPuertoServidor (ClientConfFileManagerTest)" << std::endl;

    std::cout << "%TEST_STARTED% testSetUsuario (ClientConfFileManagerTest)" << std::endl;
    testSetUsuario();
    std::cout << "%TEST_FINISHED% time=0 testSetUsuario (ClientConfFileManagerTest)" << std::endl;
    
    
    std::cout << "%TEST_STARTED% testGetIntervaloPolling (ClientConfFileManagerTest)" << std::endl;
    testGetIntervaloPolling();
    std::cout << "%TEST_FINISHED% time=0 testGetIntervaloPolling (ClientConfFileManagerTest)" << std::endl;

    std::cout << "%TEST_STARTED% testGetIpServidor (ClientConfFileManagerTest)" << std::endl;
    testGetIpServidor();
    std::cout << "%TEST_FINISHED% time=0 testGetIpServidor (ClientConfFileManagerTest)" << std::endl;

    std::cout << "%TEST_STARTED% testGetPassword (ClientConfFileManagerTest)" << std::endl;
    testGetPassword();
    std::cout << "%TEST_FINISHED% time=0 testGetPassword (ClientConfFileManagerTest)" << std::endl;

    std::cout << "%TEST_STARTED% testGetPathAU (ClientConfFileManagerTest)" << std::endl;
    testGetPathAU();
    std::cout << "%TEST_FINISHED% time=0 testGetPathAU (ClientConfFileManagerTest)" << std::endl;

    std::cout << "%TEST_STARTED% testGetPuertoServidor (ClientConfFileManagerTest)" << std::endl;
    testGetPuertoServidor();
    std::cout << "%TEST_FINISHED% time=0 testGetPuertoServidor (ClientConfFileManagerTest)" << std::endl;

    std::cout << "%TEST_STARTED% testGetUsuario (ClientConfFileManagerTest)" << std::endl;
    testGetUsuario();
    std::cout << "%TEST_FINISHED% time=0 testGetUsuario (ClientConfFileManagerTest)" << std::endl;

    std::cout << "%SUITE_FINISHED% time=0" << std::endl;

    return (EXIT_SUCCESS);
}